package com.hdc.hdc.warehouseManage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hdc.hdc.warehouseManage.entity.vo.WareHouseVO;
import com.hdc.hdc.warehouseManage.service.GoodsLocationServiceI;
import com.hdc.hdc.warehouseManage.utill.AjaxReturnVO;

/**
 * 货位Controller 
 * @author gxy
 *	2018年4月20日
 *	hdc.warehouseManage
 *
 */
@RestController
@RequestMapping(value="/goodsLocationController")
public class GoodsLocationController {
	
	@Autowired
	private GoodsLocationServiceI goodLocationServiceI;
	
	@RequestMapping(value="/getGoodLocation")
	public AjaxReturnVO getGoodLocation() {
		
		AjaxReturnVO vo = new AjaxReturnVO();
		
		try {
			vo.setOk(true);
			vo.setData(this.goodLocationServiceI.findGoodLocation());
		} catch (Exception e) {
			e.printStackTrace();
			vo.setOk(false);
			vo.setMsg("查询失败:"+e.getMessage());
		}
		
		return vo;
	}
	
	@GetMapping(value="/showLocationsGoods")
	public AjaxReturnVO showGoodsByLocationId(@RequestParam(name="pageNum")Integer pageNum,
			@RequestParam(name="pageSize")Integer pageSize,
			@RequestParam(name="locationId")String locationId) {
		
		AjaxReturnVO vo = new AjaxReturnVO();
		
		try {
			vo.setOk(true);
			vo.setData(this.goodLocationServiceI.findGoodsTradeByLocation(pageNum-1,pageSize,locationId));
		} catch (Exception e) {
			e.printStackTrace();
			vo.setOk(false);
			vo.setMsg("查询失败:"+e.getMessage());
		}
		
		return vo;
	}
	
	@PostMapping(value="/updateGoodsTrade")
	public AjaxReturnVO updateGoodsTrade(@RequestBody WareHouseVO vo) {
		
		AjaxReturnVO j = new AjaxReturnVO();
		
		try {
			j.setOk(true);
			this.goodLocationServiceI.updateGoodsAndLocations(vo);
		} catch (Exception e) {
			e.printStackTrace();
			j.setMsg("更新失败:"+e.getMessage());
			j.setOk(false);
		}
		
		return j;
	}
	
	@RequestMapping(value="/getGoodsByHPL")
	public AjaxReturnVO getGoodsByHPL(@RequestParam(name="houseId")String houseId,
			@RequestParam(name="positionId")String positionId,@RequestParam(name="locationId")String locationId) {
		
		AjaxReturnVO j = new AjaxReturnVO();
		
		try {
			
			j.setOk(true);
			j.setData(this.goodLocationServiceI.findGoodsByHPL(houseId,positionId,locationId));
		} catch (Exception e) {
			e.printStackTrace();
			j.setFail(j, e.getMessage());
		}
		
		return j;
		
	}

}
